<!DOCTYPE html>
<html><head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    
    <link rel="canonical" href="/unity-playground/record/">

    <title>
        
        record | h-book
        
    </title>

    
    <link href="/css/fontawesome.min.css" rel="stylesheet">

    
    <link rel="stylesheet" href="/css/ace.min.css">

    

    

</head>
<body><nav class="navbar navbar-expand-lg navbar-dark bg-primary shadow sticky-top" id="navbarMain">
    <div class="container">
        <div>
            <a class="navbar-brand" href="/">
                
                h-book
            </a>
        </div>
    </div>
</nav>
<div class="container-fluid">
            <div class="row">

                <div class="docs-sidenav order-0 col-12 col-md-3 col-lg-2 col-xl-2 position-sticky border-right"><nav class="navbar navbar-expand-md navbar-light pl-0">
    <button class="navbar-toggler navbar-toggler-right collapsed" type="button" data-toggle="collapse" data-target="#sidenav-left-collapse" aria-controls="sidenav-left-collapse" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>

     <div class="collapse navbar-collapse align-items-start flex-column" id="sidenav-left-collapse">
            <form class="form-inline my-2 my-lg-0 searchbox">
                <input class="form-control mr-sm-2 w-100" data-search-input id="search-by" type="text" placeholder="Search">
            </form>

        

         <ul class="navbar-nav flex-column pt-3">
    <li data-nav-id="/hugo/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/hugo/"><h6>Hugo</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/hugo/init/" class="nav-item my-1">
                
                
                  <a href="/hugo/init/" class="nav-link p-0">
                    init
                  </a>
                
        </li>
        <li data-nav-id="/hugo/add-page/" class="nav-item my-1">
                
                
                  <a href="/hugo/add-page/" class="nav-link p-0">
                    add-page
                  </a>
                
        </li>
        <li data-nav-id="/hugo/edit-skill/" class="nav-item my-1">
                
                
                  <a href="/hugo/edit-skill/" class="nav-link p-0">
                    edit-skill
                  </a>
                
        </li>
        <li data-nav-id="/hugo/publish/" class="nav-item my-1">
                
                
                  <a href="/hugo/publish/" class="nav-link p-0">
                    publish
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/android/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/android/"><h6>Android</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/android/install/" class="nav-item my-1">
                
                
                  <a href="/android/install/" class="nav-link p-0">
                    install
                  </a>
                
        </li>
        <li data-nav-id="/android/create-project/" class="nav-item my-1">
                
                
                  <a href="/android/create-project/" class="nav-link p-0">
                    create project
                  </a>
                
        </li>
        <li data-nav-id="/android/import-material/" class="nav-item my-1">
                
                
                  <a href="/android/import-material/" class="nav-link p-0">
                    import material
                  </a>
                
        </li>
        <li data-nav-id="/android/start-page/" class="nav-item my-1">
                
                
                  <a href="/android/start-page/" class="nav-link p-0">
                    startpage
                  </a>
                
        </li>
        <li data-nav-id="/android/i18n/" class="nav-item my-1">
                
                
                  <a href="/android/i18n/" class="nav-link p-0">
                    i18n
                  </a>
                
        </li>
        <li data-nav-id="/android/nav-flat-page/" class="nav-item my-1">
                
                
                  <a href="/android/nav-flat-page/" class="nav-link p-0">
                    nav flat page
                  </a>
                
        </li>
        <li data-nav-id="/android/activity/" class="nav-item my-1">
                
                
                  <a href="/android/activity/" class="nav-link p-0">
                    Activity
                  </a>
                
        </li>
        <li data-nav-id="/android/db/" class="nav-item my-1">
                
                
                  <a href="/android/db/" class="nav-link p-0">
                    DB
                  </a>
                
        </li>
        <li data-nav-id="/android/dialog/" class="nav-item my-1">
                
                
                  <a href="/android/dialog/" class="nav-link p-0">
                    Dialog
                  </a>
                
        </li>
        <li data-nav-id="/android/fragment/" class="nav-item my-1">
                
                
                  <a href="/android/fragment/" class="nav-link p-0">
                    Fragment
                  </a>
                
        </li>
        <li data-nav-id="/android/jetpack/" class="nav-item my-1">
                
                
                  <a href="/android/jetpack/" class="nav-link p-0">
                    Jetpack
                  </a>
                
        </li>
        <li data-nav-id="/android/material/" class="nav-item my-1">
                
                
                  <a href="/android/material/" class="nav-link p-0">
                    Material
                  </a>
                
        </li>
        <li data-nav-id="/android/storage/" class="nav-item my-1">
                
                
                  <a href="/android/storage/" class="nav-link p-0">
                    Storage
                  </a>
                
        </li>
        <li data-nav-id="/android/%E5%9B%BE%E6%A0%87/" class="nav-item my-1">
                
                
                  <a href="/android/%E5%9B%BE%E6%A0%87/" class="nav-link p-0">
                    图标
                  </a>
                
        </li>
        <li data-nav-id="/android/store/" class="nav-item my-1">
                
                
                  <a href="/android/store/" class="nav-link p-0">
                    Store
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/blender/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/blender/"><h6>Blender</h6></a>
        
    </li>
    <li data-nav-id="/bootstrap/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/bootstrap/"><h6>BootStrap</h6></a>
        
    </li>
    <li data-nav-id="/centos7/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/centos7/"><h6>Centos7</h6></a>
        
    </li>
    <li data-nav-id="/dlna/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/dlna/"><h6>DLNA</h6></a>
        
    </li>
    <li data-nav-id="/docker/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/docker/"><h6>Docker</h6></a>
        
    </li>
    <li data-nav-id="/dubbo/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/dubbo/"><h6>Dubbo</h6></a>
        
    </li>
    <li data-nav-id="/ffmpeg/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/ffmpeg/"><h6>FFmpeg</h6></a>
        
    </li>
    <li data-nav-id="/git/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/git/"><h6>Git</h6></a>
        
    </li>
    <li data-nav-id="/gitbook/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/gitbook/"><h6>Gitbook</h6></a>
        
    </li>
    <li data-nav-id="/gitlab/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/gitlab/"><h6>Gitlab</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/gitlab/runner/" class="nav-item my-1">
                
                
                  <a href="/gitlab/runner/" class="nav-link p-0">
                    Runner
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/gradle/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/gradle/"><h6>Gradle</h6></a>
        
    </li>
    <li data-nav-id="/java/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/java/"><h6>Java</h6></a>
        
    </li>
    <li data-nav-id="/jenkins/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/jenkins/"><h6>Jenkins</h6></a>
        
    </li>
    <li data-nav-id="/kubernetes/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/kubernetes/"><h6>Kubernetes</h6></a>
        
    </li>
    <li data-nav-id="/mybatis/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/mybatis/"><h6>Mybatis</h6></a>
        
    </li>
    <li data-nav-id="/mybatis-plus/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/mybatis-plus/"><h6>Mybatis Plus</h6></a>
        
    </li>
    <li data-nav-id="/mysql/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/mysql/"><h6>MySQL</h6></a>
        
    </li>
    <li data-nav-id="/nodejs/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/nodejs/"><h6>Node.js</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/nodejs/npm/" class="nav-item my-1">
                
                
                  <a href="/nodejs/npm/" class="nav-link p-0">
                    NPM
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/postgresql/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/postgresql/"><h6>PostgreSQL</h6></a>
        
    </li>
    <li data-nav-id="/redis/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/redis/"><h6>Redis</h6></a>
        
    </li>
    <li data-nav-id="/samba/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/samba/"><h6>Samba</h6></a>
        
    </li>
    <li data-nav-id="/sql/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/sql/"><h6>SQL</h6></a>
        
    </li>
    <li data-nav-id="/ue5/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/ue5/"><h6>UE5</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/ue5/install/" class="nav-item my-1">
                
                
                  <a href="/ue5/install/" class="nav-link p-0">
                    install
                  </a>
                
        </li>
        <li data-nav-id="/ue5/uninstall/" class="nav-item my-1">
                
                
                  <a href="/ue5/uninstall/" class="nav-link p-0">
                    uninstall
                  </a>
                
        </li>
        <li data-nav-id="/ue5/qa/" class="nav-item my-1">
                
                
                  <a href="/ue5/qa/" class="nav-link p-0">
                    Q&amp;A
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity/"><h6>Unity</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity/install/" class="nav-item my-1">
                
                
                  <a href="/unity/install/" class="nav-link p-0">
                    install
                  </a>
                
        </li>
        <li data-nav-id="/unity/scene/" class="nav-item my-1">
                
                
                  <a href="/unity/scene/" class="nav-link p-0">
                    scene
                  </a>
                
        </li>
        <li data-nav-id="/unity/inspector/" class="nav-item my-1">
                
                
                  <a href="/unity/inspector/" class="nav-link p-0">
                    inspector
                  </a>
                
        </li>
        <li data-nav-id="/unity/assets/" class="nav-item my-1">
                
                
                  <a href="/unity/assets/" class="nav-link p-0">
                    assets
                  </a>
                
        </li>
        <li data-nav-id="/unity/audio-source/" class="nav-item my-1">
                
                
                  <a href="/unity/audio-source/" class="nav-link p-0">
                    audio source
                  </a>
                
        </li>
        <li data-nav-id="/unity/camera/" class="nav-item my-1">
                
                
                  <a href="/unity/camera/" class="nav-link p-0">
                    camera
                  </a>
                
        </li>
        <li data-nav-id="/unity/script/" class="nav-item my-1">
                
                
                  <a href="/unity/script/" class="nav-link p-0">
                    script
                  </a>
                
        </li>
        <li data-nav-id="/unity/prefabs/" class="nav-item my-1">
                
                
                  <a href="/unity/prefabs/" class="nav-link p-0">
                    prefabs
                  </a>
                
        </li>
        <li data-nav-id="/unity/physics/" class="nav-item my-1">
                
                
                  <a href="/unity/physics/" class="nav-link p-0">
                    physics
                  </a>
                
        </li>
        <li data-nav-id="/unity/skybox/" class="nav-item my-1">
                
                
                  <a href="/unity/skybox/" class="nav-link p-0">
                    skybox
                  </a>
                
        </li>
        <li data-nav-id="/unity/particle-system/" class="nav-item my-1">
                
                
                  <a href="/unity/particle-system/" class="nav-link p-0">
                    particle system
                  </a>
                
        </li>
        <li data-nav-id="/unity/shortcut-keys/" class="nav-item my-1">
                
                
                  <a href="/unity/shortcut-keys/" class="nav-link p-0">
                    shortcut keys
                  </a>
                
        </li>
        <li data-nav-id="/unity/qa/" class="nav-item my-1">
                
                
                  <a href="/unity/qa/" class="nav-link p-0">
                    Q&amp;A
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-2d-beginner/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-2d-beginner/"><h6>Unity 2D Beginner</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-2d-beginner/init-and-move/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/init-and-move/" class="nav-link p-0">
                    Init &amp; Move
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/map/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/map/" class="nav-link p-0">
                    Map
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/data/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/data/" class="nav-link p-0">
                    Data
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/animate/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/animate/" class="nav-link p-0">
                    Data
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/bullet/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/bullet/" class="nav-link p-0">
                    Bullet
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/cinemachine/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/cinemachine/" class="nav-link p-0">
                    Cinemachine
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/particle/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/particle/" class="nav-link p-0">
                    Particle
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/ui/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/ui/" class="nav-link p-0">
                    UI
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/npc/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/npc/" class="nav-link p-0">
                    NPC
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/sound/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/sound/" class="nav-link p-0">
                    Sound
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-2d-game-kit/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-2d-game-kit/"><h6>Unity 2D Game Kit</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-2d-game-kit/record/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-game-kit/record/" class="nav-link p-0">
                    record
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-3d-beginner/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-3d-beginner/"><h6>Unity 3D Beginner</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-3d-beginner/init/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/init/" class="nav-link p-0">
                    Init
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/level/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/level/" class="nav-link p-0">
                    Level
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/nav/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/nav/" class="nav-link p-0">
                    Nav
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/render-pipeline/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/render-pipeline/" class="nav-link p-0">
                    Render Pipeline
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/postprocessing/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/postprocessing/" class="nav-link p-0">
                    PostProcessing
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/ui/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/ui/" class="nav-link p-0">
                    UI
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/enemy/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/enemy/" class="nav-link p-0">
                    Enemy
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/sound/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/sound/" class="nav-link p-0">
                    Sound
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/%E5%BB%BA%E6%A8%A1%E5%B7%A5%E5%85%B7/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/%E5%BB%BA%E6%A8%A1%E5%B7%A5%E5%85%B7/" class="nav-link p-0">
                    建模工具
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-arpg/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-arpg/"><h6>Unity ARPG</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-arpg/init/" class="nav-item my-1">
                
                
                  <a href="/unity-arpg/init/" class="nav-link p-0">
                    Init
                  </a>
                
        </li>
        <li data-nav-id="/unity-arpg/role-state-machine/" class="nav-item my-1">
                
                
                  <a href="/unity-arpg/role-state-machine/" class="nav-link p-0">
                    Role State Machine
                  </a>
                
        </li>
        <li data-nav-id="/unity-arpg/api-piece/" class="nav-item my-1">
                
                
                  <a href="/unity-arpg/api-piece/" class="nav-link p-0">
                    API Piece
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-creativecore-animation/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-creativecore-animation/"><h6>Unity Creativecore Animation</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-creativecore-animation/door/" class="nav-item my-1">
                
                
                  <a href="/unity-creativecore-animation/door/" class="nav-link p-0">
                    Door
                  </a>
                
        </li>
        <li data-nav-id="/unity-creativecore-animation/init/" class="nav-item my-1">
                
                
                  <a href="/unity-creativecore-animation/init/" class="nav-link p-0">
                    Init
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-creativecore-lighting/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-creativecore-lighting/"><h6>Unity Creativecore Lighting</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-creativecore-lighting/init/" class="nav-item my-1">
                
                
                  <a href="/unity-creativecore-lighting/init/" class="nav-link p-0">
                    Init
                  </a>
                
        </li>
        <li data-nav-id="/unity-creativecore-lighting/outdoor/" class="nav-item my-1">
                
                
                  <a href="/unity-creativecore-lighting/outdoor/" class="nav-link p-0">
                    Outdoor
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-creativecore-shader/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-creativecore-shader/"><h6>Unity Creativecore Shader</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-creativecore-shader/init/" class="nav-item my-1">
                
                
                  <a href="/unity-creativecore-shader/init/" class="nav-link p-0">
                    Init
                  </a>
                
        </li>
        <li data-nav-id="/unity-creativecore-shader/glass/" class="nav-item my-1">
                
                
                  <a href="/unity-creativecore-shader/glass/" class="nav-link p-0">
                    Glass
                  </a>
                
        </li>
        <li data-nav-id="/unity-creativecore-shader/shader-graph/" class="nav-item my-1">
                
                
                  <a href="/unity-creativecore-shader/shader-graph/" class="nav-link p-0">
                    Shader-Graph
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-creator-kit-beginner-code/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-creator-kit-beginner-code/"><h6>Unity Creator Kit Beginner Code</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-creator-kit-beginner-code/record/" class="nav-item my-1">
                
                
                  <a href="/unity-creator-kit-beginner-code/record/" class="nav-link p-0">
                    record
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-creator-kit-fps/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-creator-kit-fps/"><h6>Unity Creator Kit FPS</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-creator-kit-fps/record/" class="nav-item my-1">
                
                
                  <a href="/unity-creator-kit-fps/record/" class="nav-link p-0">
                    record
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-mythirdperson/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-mythirdperson/"><h6>Unity My Third Person</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-mythirdperson/init/" class="nav-item my-1">
                
                
                  <a href="/unity-mythirdperson/init/" class="nav-link p-0">
                    Init
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-playground/" class="nav-item my-1 parent haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-playground/"><h6>Unity Playground</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-playground/record/" class="nav-item my-1 active">
                
                
                  <a href="/unity-playground/record/" class="nav-link p-0">
                    record
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-ui/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-ui/"><h6>Unity UI</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-ui/init/" class="nav-item my-1">
                
                
                  <a href="/unity-ui/init/" class="nav-link p-0">
                    record
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-vfx/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-vfx/"><h6>Unity VFX</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-vfx/init/" class="nav-item my-1">
                
                
                  <a href="/unity-vfx/init/" class="nav-link p-0">
                    record
                  </a>
                
        </li>
        <li data-nav-id="/unity-vfx/bullet/" class="nav-item my-1">
                
                
                  <a href="/unity-vfx/bullet/" class="nav-link p-0">
                    bullet
                  </a>
                
        </li>
        <li data-nav-id="/unity-vfx/rain/" class="nav-item my-1">
                
                
                  <a href="/unity-vfx/rain/" class="nav-link p-0">
                    rain
                  </a>
                
        </li>
        <li data-nav-id="/unity-vfx/rock-rain/" class="nav-item my-1">
                
                
                  <a href="/unity-vfx/rock-rain/" class="nav-link p-0">
                    Rock Rain
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/vue/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/vue/"><h6>Vue</h6></a>
        
    </li>
    <li data-nav-id="/web/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/web/"><h6>Web</h6></a>
        
    </li>
        </ul>
    </div>
</nav>


</div>
                <div class="docs-toc large order-lg-2 order-md-0 order-xs-1 col-12 col-lg-2 col-xl-2 position-sticky border-left"><div class="docs-toc">
	<nav id="TableOfContents">
  <ul>
    <li><a href="#导入">导入</a></li>
    <li><a href="#添加飞机">添加飞机</a>
      <ul>
        <li><a href="#move-脚本代码解析">Move 脚本代码解析</a></li>
        <li><a href="#healthsystemattribute-脚本代码解析">HealthSystemAttribute 脚本代码解析</a></li>
      </ul>
    </li>
    <li><a href="#添加陨石">添加陨石</a>
      <ul>
        <li><a href="#modifyhealthattribute-脚本代码解析">ModifyHealthAttribute 脚本代码解析</a></li>
      </ul>
    </li>
    <li><a href="#添加星星">添加星星</a>
      <ul>
        <li><a href="#collectableattribute-脚本解析">CollectableAttribute 脚本解析</a></li>
      </ul>
    </li>
    <li><a href="#添加-ui">添加 UI</a>
      <ul>
        <li><a href="#uiscript-脚本解析">UIScript 脚本解析</a></li>
      </ul>
    </li>
    <li><a href="#添加背景">添加背景</a>
      <ul>
        <li><a href="#9-切片精灵">9 切片精灵</a></li>
      </ul>
    </li>
  </ul>
</nav>
</div>
</div>
                <div class="main col-12 order-1 col-md-9 col-lg-10 col-xl-8 py-3">
                

<div class="d-flex flex-column">
    <h1 class="js-title">record</h1>
    <div class="d-flex align-items-center">
        
    </div>
</div>

<hr>


<p>2024.08.17</p>
<h2 id="导入">导入</h2>
<ol>
<li>使用 2022.3.40f1</li>
<li>新建 2D 工程</li>
<li>将工程拖拽到 Assets</li>
<li>允许导入和升级依赖模块</li>
<li>自动升级代码</li>
</ol>
<p>得如下结构</p>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-txt" data-lang="txt"><span style="display:flex;"><span>- Asssets
</span></span><span style="display:flex;"><span>  - _INTERNAL_
</span></span><span style="display:flex;"><span>  - Documentation
</span></span><span style="display:flex;"><span>  - Examples
</span></span><span style="display:flex;"><span>  - Images
</span></span><span style="display:flex;"><span>  - Prefabs
</span></span><span style="display:flex;"><span>  - Resources
</span></span><span style="display:flex;"><span>  - Scenes
</span></span><span style="display:flex;"><span>  - Scripts
</span></span></code></pre></div><h2 id="添加飞机">添加飞机</h2>
<ol>
<li>删除 Scenes/SampleScene</li>
<li>创建 Scenes/PlaneAsteroid</li>
<li>从 Images/Spaceships/SpaceshipRed 创建一个对象，改名为 Ship ，Tag 为 Player ，修改缩放为 0.1 （以 1K 屏幕为基准）</li>
<li>将 Scripts/Movement/Move 添加到 Ship 上，得两个新组建 Rigidbody2D 和 Move With Arrows 。再添加 Box Collider 2D</li>
</ol>
<ul>
<li>Rigidbody2D
<ul>
<li>Gravity 设置为 0 防止不操作时按重力向下移动</li>
<li>Friction 设置为 5 增加摩擦力</li>
</ul>
</li>
<li>Move With Arrows
<ul>
<li>Type Of Control 设置为 WASD</li>
<li>Speed 改为 3</li>
</ul>
</li>
</ul>
<ol start="5">
<li>启动游戏能得到比较好的操控</li>
<li>添加一个 Scripts/Attributes/HealthSystemAttribute 脚本</li>
</ol>
<h3 id="move-脚本代码解析">Move 脚本代码解析</h3>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cs" data-lang="cs"><span style="display:flex;"><span><span style="color:#75715e">// 用来显示脚本的名称为 Move With Arrows</span>
</span></span><span style="display:flex;"><span><span style="color:#75af00">[AddComponentMenu(&#34;Playground/Movement/Move With Arrows&#34;)]</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">// 父类 _INTERNAL_/Scripts/BaseClasses/Physics2DObject.cs</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">/*
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// 依赖 Rigidbody2D 模块，所以添加该模块后会额外添加 Rigidbody2D 模块
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">[RequireComponent(typeof(Rigidbody2D))]
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">public abstract class Physics2DObject : MonoBehaviour
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">{
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">	[HideInInspector]
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">	public new Rigidbody2D rigidbody2D;
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">	void Awake ()
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">	{
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">		rigidbody2D = GetComponent&lt;Rigidbody2D&gt;();
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">	}
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">}
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">*/</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">public</span> <span style="color:#00a8c8">class</span> <span style="color:#75af00">Move</span> <span style="color:#111">:</span> <span style="color:#111">Physics2DObject</span>
</span></span><span style="display:flex;"><span><span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// 定义输入按键类型。枚举是定义在 _INTERNAL_/Scripts/Utilities/Enums.cs 中的</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">/*
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">  public class Enums
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">  {
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">    public enum KeyGroups
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">    {
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">      ArrowKeys,
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">      WASD,
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">    }
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">  }
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">  */</span>
</span></span><span style="display:flex;"><span><span style="color:#75af00">  [Header(&#34;Input keys&#34;)]</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">public</span> <span style="color:#111">Enums</span><span style="color:#111">.</span><span style="color:#111">KeyGroups</span> <span style="color:#111">typeOfControl</span> <span style="color:#111">=</span> <span style="color:#111">Enums</span><span style="color:#111">.</span><span style="color:#111">KeyGroups</span><span style="color:#111">.</span><span style="color:#111">ArrowKeys</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// 朝向，匹配按键方向</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">/*
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">  public class Enums
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">  {
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">    public enum Directions
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">    {
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">      Up,
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">      Right,
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">      Down,
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">      Left,
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">    }
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">  }
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">  */</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">public</span> <span style="color:#111">Enums</span><span style="color:#111">.</span><span style="color:#111">Directions</span> <span style="color:#111">lookAxis</span> <span style="color:#111">=</span> <span style="color:#111">Enums</span><span style="color:#111">.</span><span style="color:#111">Directions</span><span style="color:#111">.</span><span style="color:#111">Up</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">void</span> <span style="color:#111">Update</span> <span style="color:#111">()</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">// 根据按键类型获取水平和垂直方向的输入</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">if</span><span style="color:#111">(</span><span style="color:#111">typeOfControl</span> <span style="color:#111">==</span> <span style="color:#111">Enums</span><span style="color:#111">.</span><span style="color:#111">KeyGroups</span><span style="color:#111">.</span><span style="color:#111">ArrowKeys</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>      <span style="color:#111">moveHorizontal</span> <span style="color:#111">=</span> <span style="color:#111">Input</span><span style="color:#111">.</span><span style="color:#111">GetAxis</span><span style="color:#111">(</span><span style="color:#d88200">&#34;Horizontal&#34;</span><span style="color:#111">);</span> <span style="color:#75715e">// 私有变量 private float moveHorizontal</span>
</span></span><span style="display:flex;"><span>      <span style="color:#111">moveVertical</span> <span style="color:#111">=</span> <span style="color:#111">Input</span><span style="color:#111">.</span><span style="color:#111">GetAxis</span><span style="color:#111">(</span><span style="color:#d88200">&#34;Vertical&#34;</span><span style="color:#111">);</span> <span style="color:#75715e">// 同上</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">else</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>      <span style="color:#111">moveHorizontal</span> <span style="color:#111">=</span> <span style="color:#111">Input</span><span style="color:#111">.</span><span style="color:#111">GetAxis</span><span style="color:#111">(</span><span style="color:#d88200">&#34;Horizontal2&#34;</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>      <span style="color:#111">moveVertical</span> <span style="color:#111">=</span> <span style="color:#111">Input</span><span style="color:#111">.</span><span style="color:#111">GetAxis</span><span style="color:#111">(</span><span style="color:#d88200">&#34;Vertical2&#34;</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">// 做出移动的响应，注释该行后将无法操控</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">movement</span> <span style="color:#111">=</span> <span style="color:#00a8c8">new</span> <span style="color:#111">Vector2</span><span style="color:#111">(</span><span style="color:#111">moveHorizontal</span><span style="color:#111">,</span> <span style="color:#111">moveVertical</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">// 如果开启移动时调整朝向</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">if</span><span style="color:#111">(</span><span style="color:#111">orientToDirection</span><span style="color:#111">)</span> <span style="color:#75715e">// boolean 变量</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>      <span style="color:#00a8c8">if</span><span style="color:#111">(</span><span style="color:#111">movement</span><span style="color:#111">.</span><span style="color:#111">sqrMagnitude</span> <span style="color:#111">&gt;=</span> <span style="color:#ae81ff">0.01f</span><span style="color:#111">)</span> <span style="color:#75715e">// 向量平方长度大于 0.01f</span>
</span></span><span style="display:flex;"><span>      <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">cachedDirection</span> <span style="color:#111">=</span> <span style="color:#111">movement</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>      <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>      <span style="color:#75715e">// 调整旋转 _INTERNAL_/Scripts/Utilities/Utils.cs </span>
</span></span><span style="display:flex;"><span>      <span style="color:#75715e">/*
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">      public static class Utils
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">      {
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">        public static void SetAxisTowards(Enums.Directions axis, Transform t, Vector2 direction)
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">        {
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">          switch(axis)
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">          {
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">            case Enums.Directions.Up:
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">              t.up = direction; // 2D 游戏中，up 是 Y 轴，right 是 X 轴
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">              break;
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">            case Enums.Directions.Down:
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">              t.up = -direction;
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">              break;
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">            case Enums.Directions.Right:
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">              t.right = direction;
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">              break;
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">            case Enums.Directions.Left:
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">              t.right = -direction;
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">              break;
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">          }
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">        }    
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">      }
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">      */</span>
</span></span><span style="display:flex;"><span>      <span style="color:#111">Utils</span><span style="color:#111">.</span><span style="color:#111">SetAxisTowards</span><span style="color:#111">(</span><span style="color:#111">lookAxis</span><span style="color:#111">,</span> <span style="color:#111">transform</span><span style="color:#111">,</span> <span style="color:#111">cachedDirection</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span></code></pre></div><h3 id="healthsystemattribute-脚本代码解析">HealthSystemAttribute 脚本代码解析</h3>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cs" data-lang="cs"><span style="display:flex;"><span><span style="color:#75715e">// 设定当前血量</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">public</span> <span style="color:#00a8c8">int</span> <span style="color:#111">health</span> <span style="color:#111">=</span> <span style="color:#ae81ff">3</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">// ui 模块的引用</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">private</span> <span style="color:#111">UIScript</span> <span style="color:#111">ui</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">// 玩家数量，0表示1个，1表示2个，-1则是没有</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">private</span> <span style="color:#00a8c8">int</span> <span style="color:#111">playerNumber</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">// 设定血量上限</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">private</span> <span style="color:#00a8c8">int</span> <span style="color:#111">maxHealth</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">private</span> <span style="color:#00a8c8">void</span> <span style="color:#111">Start</span><span style="color:#111">()</span>
</span></span><span style="display:flex;"><span><span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// 赋值 ui 引用</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">ui</span> <span style="color:#111">=</span> <span style="color:#111">GameObject</span><span style="color:#111">.</span><span style="color:#111">FindObjectOfType</span><span style="color:#111">&lt;</span><span style="color:#111">UIScript</span><span style="color:#111">&gt;();</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">switch</span><span style="color:#111">(</span><span style="color:#111">gameObject</span><span style="color:#111">.</span><span style="color:#111">tag</span><span style="color:#111">)</span> <span style="color:#75715e">// 根据 tag 定玩家 ID</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">case</span> <span style="color:#d88200">&#34;Player&#34;</span><span style="color:#111">:</span>
</span></span><span style="display:flex;"><span>      <span style="color:#111">playerNumber</span> <span style="color:#111">=</span> <span style="color:#ae81ff">0</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>      <span style="color:#00a8c8">break</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">case</span> <span style="color:#d88200">&#34;Player2&#34;</span><span style="color:#111">:</span>
</span></span><span style="display:flex;"><span>      <span style="color:#111">playerNumber</span> <span style="color:#111">=</span> <span style="color:#ae81ff">1</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>      <span style="color:#00a8c8">break</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">default</span><span style="color:#111">:</span>
</span></span><span style="display:flex;"><span>      <span style="color:#111">playerNumber</span> <span style="color:#111">=</span> <span style="color:#111">-</span><span style="color:#ae81ff">1</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>      <span style="color:#00a8c8">break</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">if</span><span style="color:#111">(</span><span style="color:#111">ui</span> <span style="color:#111">!=</span> <span style="color:#00a8c8">null</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">&amp;&amp;</span> <span style="color:#111">playerNumber</span> <span style="color:#111">!=</span> <span style="color:#111">-</span><span style="color:#ae81ff">1</span><span style="color:#111">)</span> <span style="color:#75715e">// 存在 ui 模块且有玩家</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">ui</span><span style="color:#111">.</span><span style="color:#111">SetHealth</span><span style="color:#111">(</span><span style="color:#111">health</span><span style="color:#111">,</span> <span style="color:#111">playerNumber</span><span style="color:#111">);</span> <span style="color:#75715e">// 设定 ui 显示</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">maxHealth</span> <span style="color:#111">=</span> <span style="color:#111">health</span><span style="color:#111">;</span> <span style="color:#75715e">// 设定最大血量</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">// 暴露修改血量的方法，会在 Scripts\Attributes\ModifyHealthAttribute.cs 中调用</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">public</span> <span style="color:#00a8c8">void</span> <span style="color:#111">ModifyHealth</span><span style="color:#111">(</span><span style="color:#00a8c8">int</span> <span style="color:#111">amount</span><span style="color:#111">)</span> <span style="color:#75715e">// 撞陨石会进来 -1</span>
</span></span><span style="display:flex;"><span><span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">health</span> <span style="color:#111">+=</span> <span style="color:#111">amount</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// 修改 UI 的显示</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">if</span><span style="color:#111">(</span><span style="color:#111">ui</span> <span style="color:#111">!=</span> <span style="color:#00a8c8">null</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">&amp;&amp;</span> <span style="color:#111">playerNumber</span> <span style="color:#111">!=</span> <span style="color:#111">-</span><span style="color:#ae81ff">1</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">ui</span><span style="color:#111">.</span><span style="color:#111">ChangeHealth</span><span style="color:#111">(</span><span style="color:#111">amount</span><span style="color:#111">,</span> <span style="color:#111">playerNumber</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// 没血了自毁</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">if</span><span style="color:#111">(</span><span style="color:#111">health</span> <span style="color:#111">&lt;=</span> <span style="color:#ae81ff">0</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">Destroy</span><span style="color:#111">(</span><span style="color:#111">gameObject</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span></code></pre></div><h2 id="添加陨石">添加陨石</h2>
<ol>
<li>从 Images/Asteroids/Asteroid2 创建一个对象，修改缩放为 0.5 ，随便移动下位置</li>
<li>为这个对象添加 Scripts/Attributes/ModifyHealthAttribute 脚本， 选择 Polygon ，再添加 Rigidbody 2D</li>
</ol>
<ul>
<li>Polygon Collider 2D
<ul>
<li>Is Trigger 设置为 false 。如果为 true 则只检测触碰，不会有物理反映（传过去）</li>
</ul>
</li>
<li>Rigidbody 2D
<ul>
<li>Mass 设置为 10</li>
<li>Friction 设置为 5</li>
<li>Angular Friction 设置为 0.5</li>
<li>Gravity 设置为 0</li>
</ul>
</li>
</ul>
<h3 id="modifyhealthattribute-脚本代码解析">ModifyHealthAttribute 脚本代码解析</h3>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cs" data-lang="cs"><span style="display:flex;"><span><span style="color:#75715e">// 碰撞后是否销毁</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">public</span> <span style="color:#00a8c8">bool</span> <span style="color:#111">destroyWhenActivated</span> <span style="color:#111">=</span> <span style="color:#00a8c8">false</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">// 碰撞后血量调整值</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">public</span> <span style="color:#00a8c8">int</span> <span style="color:#111">healthChange</span> <span style="color:#111">=</span> <span style="color:#111">-</span><span style="color:#ae81ff">1</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">private</span> <span style="color:#00a8c8">void</span> <span style="color:#111">OnCollisionEnter2D</span><span style="color:#111">(</span><span style="color:#111">Collision2D</span> <span style="color:#111">collisionData</span><span style="color:#111">)</span> <span style="color:#75715e">// 碰撞回调</span>
</span></span><span style="display:flex;"><span><span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">OnTriggerEnter2D</span><span style="color:#111">(</span><span style="color:#111">collisionData</span><span style="color:#111">.</span><span style="color:#111">collider</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">private</span> <span style="color:#00a8c8">void</span> <span style="color:#111">OnTriggerEnter2D</span><span style="color:#111">(</span><span style="color:#111">Collider2D</span> <span style="color:#111">colliderData</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span><span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">HealthSystemAttribute</span> <span style="color:#111">healthScript</span> <span style="color:#111">=</span> <span style="color:#111">colliderData</span><span style="color:#111">.</span><span style="color:#111">gameObject</span><span style="color:#111">.</span><span style="color:#111">GetComponent</span><span style="color:#111">&lt;</span><span style="color:#111">HealthSystemAttribute</span><span style="color:#111">&gt;();</span> <span style="color:#75715e">// 获取飞机上的 HealthSystemAttribute 组件</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">if</span><span style="color:#111">(</span><span style="color:#111">healthScript</span> <span style="color:#111">!=</span> <span style="color:#00a8c8">null</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">healthScript</span><span style="color:#111">.</span><span style="color:#111">ModifyHealth</span><span style="color:#111">(</span><span style="color:#111">healthChange</span><span style="color:#111">);</span> <span style="color:#75715e">// 调用修改血量的方法</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">if</span><span style="color:#111">(</span><span style="color:#111">destroyWhenActivated</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>      <span style="color:#111">Destroy</span><span style="color:#111">(</span><span style="color:#00a8c8">this</span><span style="color:#111">.</span><span style="color:#111">gameObject</span><span style="color:#111">);</span> <span style="color:#75715e">// 销毁本陨石</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span></code></pre></div><h2 id="添加星星">添加星星</h2>
<ol>
<li>从 Iamges/GameElements/Star 添加 1 个星星</li>
<li>给星星添加 Ploygon Collider 2D 和 Assets/Scripts/Attributes/CollectableAttribute 组件。不需要刚体</li>
</ol>
<ul>
<li>Ploygon Collider 2D
<ul>
<li>Is Trigger 设置为 true 。不受物理影响</li>
</ul>
</li>
</ul>
<ol start="3">
<li>将这个星星物体创建为预制体，然后赋值4个</li>
</ol>
<h3 id="collectableattribute-脚本解析">CollectableAttribute 脚本解析</h3>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cs" data-lang="cs"><span style="display:flex;"><span><span style="color:#75715e">// 分值</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">public</span> <span style="color:#00a8c8">int</span> <span style="color:#111">pointsWorth</span> <span style="color:#111">=</span> <span style="color:#ae81ff">1</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">// ui 模块引用</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">private</span> <span style="color:#111">UIScript</span> <span style="color:#111">userInterface</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">// 启动时获取 ui 对象</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">private</span> <span style="color:#00a8c8">void</span> <span style="color:#111">Start</span><span style="color:#111">()</span>
</span></span><span style="display:flex;"><span><span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">userInterface</span> <span style="color:#111">=</span> <span style="color:#111">GameObject</span><span style="color:#111">.</span><span style="color:#111">FindObjectOfType</span><span style="color:#111">&lt;</span><span style="color:#111">UIScript</span><span style="color:#111">&gt;();</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">// 碰撞回调</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">private</span> <span style="color:#00a8c8">void</span> <span style="color:#111">OnTriggerEnter2D</span><span style="color:#111">(</span><span style="color:#111">Collider2D</span> <span style="color:#111">otherCollider</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span><span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">string</span> <span style="color:#111">playerTag</span> <span style="color:#111">=</span> <span style="color:#111">otherCollider</span><span style="color:#111">.</span><span style="color:#111">gameObject</span><span style="color:#111">.</span><span style="color:#111">tag</span><span style="color:#111">;</span> <span style="color:#75715e">// 判断标记</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// 健壮性检测</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">if</span><span style="color:#111">(</span><span style="color:#111">playerTag</span> <span style="color:#111">==</span> <span style="color:#d88200">&#34;Player&#34;</span> <span style="color:#111">||</span> <span style="color:#111">playerTag</span> <span style="color:#111">==</span> <span style="color:#d88200">&#34;Player2&#34;</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">if</span><span style="color:#111">(</span><span style="color:#111">userInterface</span> <span style="color:#111">!=</span> <span style="color:#00a8c8">null</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>      <span style="color:#75715e">// 转换为玩家 ID</span>
</span></span><span style="display:flex;"><span>      <span style="color:#00a8c8">int</span> <span style="color:#111">playerId</span> <span style="color:#111">=</span> <span style="color:#111">(</span><span style="color:#111">playerTag</span> <span style="color:#111">==</span> <span style="color:#d88200">&#34;Player&#34;</span><span style="color:#111">)</span> <span style="color:#111">?</span> <span style="color:#ae81ff">0</span> <span style="color:#111">:</span> <span style="color:#ae81ff">1</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>      <span style="color:#75715e">// 调用UI加分方法</span>
</span></span><span style="display:flex;"><span>      <span style="color:#111">userInterface</span><span style="color:#111">.</span><span style="color:#111">AddPoints</span><span style="color:#111">(</span><span style="color:#111">playerId</span><span style="color:#111">,</span> <span style="color:#111">pointsWorth</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">// 自毁</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">Destroy</span><span style="color:#111">(</span><span style="color:#111">gameObject</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span></code></pre></div><h2 id="添加-ui">添加 UI</h2>
<ol>
<li>从 Prefabs/UserInterface 添加 UI ，会带 UIScript 和 Dialogue System 脚本</li>
<li>启动游戏碰撞陨石会改变 UI 上的 health ，当减少到 0 会出现 Game over ，或者吃到 5 个星星会出现 Player X Win</li>
</ol>
<h3 id="uiscript-脚本解析">UIScript 脚本解析</h3>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cs" data-lang="cs"><span style="display:flex;"><span><span style="color:#75715e">// 判断胜利的条件（吃到星星的数量）</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">public</span> <span style="color:#00a8c8">int</span> <span style="color:#111">scoreToWin</span> <span style="color:#111">=</span> <span style="color:#ae81ff">5</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">// 玩家血量记录</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">private</span> <span style="color:#00a8c8">int</span><span style="color:#111">[]</span> <span style="color:#111">playersHealth</span> <span style="color:#111">=</span> <span style="color:#00a8c8">new</span> <span style="color:#00a8c8">int</span><span style="color:#111">[</span><span style="color:#ae81ff">2</span><span style="color:#111">];</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">// 初始化血量，会在 HealthSystemAttribute 调用</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">public</span> <span style="color:#00a8c8">void</span> <span style="color:#111">SetHealth</span><span style="color:#111">(</span><span style="color:#00a8c8">int</span> <span style="color:#111">amount</span><span style="color:#111">,</span> <span style="color:#00a8c8">int</span> <span style="color:#111">playerNumber</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span><span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">playersHealth</span><span style="color:#111">[</span><span style="color:#111">playerNumber</span><span style="color:#111">]</span> <span style="color:#111">=</span> <span style="color:#111">amount</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">// 改变血量，会在 HealthSystemAttribute 调用</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">public</span> <span style="color:#00a8c8">void</span> <span style="color:#111">ChangeHealth</span><span style="color:#111">(</span><span style="color:#00a8c8">int</span> <span style="color:#111">change</span><span style="color:#111">,</span> <span style="color:#00a8c8">int</span> <span style="color:#111">playerNumber</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span><span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">SetHealth</span><span style="color:#111">(</span><span style="color:#111">playersHealth</span><span style="color:#111">[</span><span style="color:#111">playerNumber</span><span style="color:#111">]</span> <span style="color:#111">+</span> <span style="color:#111">change</span><span style="color:#111">,</span> <span style="color:#111">playerNumber</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// 判断结束条件</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">if</span><span style="color:#111">(</span><span style="color:#111">gameType</span> <span style="color:#111">!=</span> <span style="color:#111">GameType</span><span style="color:#111">.</span><span style="color:#111">Endless</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">&amp;&amp;</span> <span style="color:#111">playersHealth</span><span style="color:#111">[</span><span style="color:#111">playerNumber</span><span style="color:#111">]</span> <span style="color:#111">&lt;=</span> <span style="color:#ae81ff">0</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">GameOver</span><span style="color:#111">(</span><span style="color:#111">playerNumber</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">// 玩家分数记录</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">private</span> <span style="color:#00a8c8">int</span><span style="color:#111">[]</span> <span style="color:#111">scores</span> <span style="color:#111">=</span> <span style="color:#00a8c8">new</span> <span style="color:#00a8c8">int</span><span style="color:#111">[</span><span style="color:#ae81ff">2</span><span style="color:#111">];</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">// 增加分数，会在 CollectableAttribute 调用</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">public</span> <span style="color:#00a8c8">void</span> <span style="color:#111">AddPoints</span><span style="color:#111">(</span><span style="color:#00a8c8">int</span> <span style="color:#111">playerNumber</span><span style="color:#111">,</span> <span style="color:#00a8c8">int</span> <span style="color:#111">amount</span> <span style="color:#111">=</span> <span style="color:#ae81ff">1</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span><span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// 加分</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">scores</span><span style="color:#111">[</span><span style="color:#111">playerNumber</span><span style="color:#111">]</span> <span style="color:#111">+=</span> <span style="color:#111">amount</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// 显示</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">if</span><span style="color:#111">(</span><span style="color:#111">numberOfPlayers</span> <span style="color:#111">==</span> <span style="color:#111">Players</span><span style="color:#111">.</span><span style="color:#111">OnePlayer</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">numberLabels</span><span style="color:#111">[</span><span style="color:#ae81ff">1</span><span style="color:#111">].</span><span style="color:#111">text</span> <span style="color:#111">=</span> <span style="color:#111">scores</span><span style="color:#111">[</span><span style="color:#111">playerNumber</span><span style="color:#111">].</span><span style="color:#111">ToString</span><span style="color:#111">();</span> <span style="color:#75715e">//with one player, the score is on the right</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">else</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">numberLabels</span><span style="color:#111">[</span><span style="color:#111">playerNumber</span><span style="color:#111">].</span><span style="color:#111">text</span> <span style="color:#111">=</span> <span style="color:#111">scores</span><span style="color:#111">[</span><span style="color:#111">playerNumber</span><span style="color:#111">].</span><span style="color:#111">ToString</span><span style="color:#111">();</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// 判断胜利</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">if</span><span style="color:#111">(</span><span style="color:#111">gameType</span> <span style="color:#111">==</span> <span style="color:#111">GameType</span><span style="color:#111">.</span><span style="color:#111">Score</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">&amp;&amp;</span> <span style="color:#111">scores</span><span style="color:#111">[</span><span style="color:#111">playerNumber</span><span style="color:#111">]</span> <span style="color:#111">&gt;=</span> <span style="color:#111">scoreToWin</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">GameWon</span><span style="color:#111">(</span><span style="color:#111">playerNumber</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span></code></pre></div><h2 id="添加背景">添加背景</h2>
<ol>
<li>从 Images/Backgrounds/BG_Space 添加背景，缩放调整为 4</li>
<li>修改 Sprite Renderer</li>
</ol>
<ul>
<li>Draw Mode 改为 Tiled 。定义精灵尺寸发生变化时的缩放方式为 <code>使 9 切片精灵的中间部分在精灵尺寸发生变化时平铺而不是缩放</code> ，在 Continuous 模式下，中间部分会均匀地平铺。</li>
<li>Visibility Option 下的 Sorting Layer 改为 Background 。不然会盖住飞机和陨石</li>
</ul>
<h3 id="9-切片精灵">9 切片精灵</h3>
<p>9 切片是一种二维技术，它允许以不同的尺寸重复使用一幅图像，而不需要准备多个Asset。它涉及到将图像分割成九个部分，以便你调整Sprite的大小时，不同的部分以不同的方式缩放或平铺（也就是以网格的形式重复），以保持Sprite的比例。这在创建图案或纹理时非常有用，比如2D环境中的墙壁或地板。</p>
<p><a href="https://docs.unity.cn/cn/2020.3/Manual/9SliceSprites.html">https://docs.unity.cn/cn/2020.3/Manual/9SliceSprites.html</a></p>


    


                    
                    <div class="row"></div> 

                </div>

            </div> 

        </div> 
<script src="/lib/jquery.min.js"></script> 
<script src="/lib/popper.min.js"></script> 

<script src="/js/bootstrap.min.js"></script> 


<script type="text/javascript" src="/plugins/lunr.min.js"></script>
<script type="text/javascript" src="/plugins/auto-complete.js"></script>
<link href="/plugins/auto-complete.css" rel="stylesheet">
<script type="text/javascript">
  
      var baseurl = "\/";
  
</script>
<script type="text/javascript" src="/plugins/search.js"></script>

<script type="text/javascript" src="/plugins/favorites.js"></script>


<script type="text/javascript" src="/plugins/clipboard.js"></script>
<script>
  new ClipboardJS('.btn');
</script>
</body>
</html>
